<?php
class Blog extends Front_Controller {
 	function __construct()
	{
		parent::__construct();
		$this->per_page = 16;
		$this->load->helper("footer_page");
		$this->load->model(array('blogs_category_model'));
	}
	function index($page = 0){	
		$base_where = array("where"=>"t1.active =1 ");
		$data['blogs']= $this->Blogs_model->get_many_by($base_where,$this->per_page, '', $page);
		
		//set up pagination
		$this->load->library('pagination');
		$config['base_url']		= site_url('blog/index');
		$config['uri_segment']	= 3;
		$config['per_page']		= $this->per_page;
		$config['total_rows']	= $data['blogs']->total_row;
		
		$config['first_link'] = '&laquo;&laquo;';
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['last_link'] = '&raquo;&raquo;';
		$config['last_tag_open'] = '<li>';
		$config['last_tag_close'] = '</li>';

		$config['full_tag_open'] = '<div class="col-xs-12 col-sm-6 col-md-6"><div class="pagination_wp"><ul class="pagination">';
		$config['full_tag_close'] = '</ul></div></div>';
		$config['cur_tag_open'] = '<li class="active"><a href="">';
		$config['cur_tag_close'] = '</a></li>';
		
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		
		$config['prev_link'] = '&laquo;';
		$config['prev_tag_open'] = '<li>';
		$config['prev_tag_close'] = '</li>';

		$config['next_link'] = '&raquo;';
		$config['next_tag_open'] = '<li>';
		$config['next_tag_close'] = '</li>';
				
		$this->pagination->initialize($config);
		$data['breadcrumb'] = array( '0'=>array('name'=>'Bài viết','url'=>'') );
		
		$data['meta']		= 'Bài viết, blogs';
		$data['seo_title']	= 'Bài viết, blogs';
		$data['page_title']	= 'Bài viết';
		
		$this->view('blog/index', $data);
	}
	function tags($tag_name,$page = 0){	
		$params["where"] = "t1.tags LIKE '%".$tag_name."%'";
		$params["limit"] = $page;
		$data['blogs']= $this->Blogs_model->get_many_by($params,$this->per_page, '', $page);
		//set up pagination
		$this->load->library('pagination');
		$config['base_url']		= site_url('blog/tags/'.$tag_name);
		$config['uri_segment']	= 4;
		$config['per_page']		= $this->per_page;
		$config['total_rows']	= $data['blogs']->total_row;
		
		$config['first_link'] = '&laquo;&laquo;';
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		$config['last_link'] = '&raquo;&raquo;';
		$config['last_tag_open'] = '<li>';
		$config['last_tag_close'] = '</li>';

		$config['full_tag_open'] = '<div class="col-xs-12 col-sm-6 col-md-6"><div class="pagination_wp"><ul class="pagination">';
		$config['full_tag_close'] = '</ul></div></div>';
		$config['cur_tag_open'] = '<li class="active"><a href="">';
		$config['cur_tag_close'] = '</a></li>';
		
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		
		$config['prev_link'] = '&laquo;';
		$config['prev_tag_open'] = '<li>';
		$config['prev_tag_close'] = '</li>';

		$config['next_link'] = '&raquo;';
		$config['next_tag_open'] = '<li>';
		$config['next_tag_close'] = '</li>';
				
		$this->pagination->initialize($config);
		$data['breadcrumb'] = array( '0'=>array('name'=>'Bài viết','url'=>'') );
		
		$data['meta']		= 'Bài viết, blogs';
		$data['seo_title']	= 'Bài viết, blogs';
		$data['page_title']	= 'Bài viết';
		
		$this->view('blog/index', $data);
	}
	function detail($slug){
		$this->load->helper("tags");
		$data['news_detail']	= $this->Blogs_model->detail($slug);
		$data["related_blogs"]  = $this->Blogs_model->related_blogs($data['news_detail']->id,$data['news_detail']->cat_id);
		$data['breadcrumb'] = array('0'=>array('name'=>'Bài viết','url'=>site_url(BLOGS)),'1'=>array('name'=>$data['news_detail']->title,'url'=>'') );
		$data['meta']		= $data['news_detail']->description;
		$data['seo_title']	= $data['news_detail']->title;
		$data['page_title']	= $data['news_detail']->title;
		$data['keyword']	= $data['news_detail']->keywords;
		$data['meta_image']	= site_url('uploads/images/medium/blogs/'.$data['news_detail']->image);
		$data["tags"]  		= get_tags_name($data["news_detail"]->tags);
		if(!empty($data["news_detail"]->product_id)){
			$data["product"]    = $this->Blogs_model->get_blogs_product($data["news_detail"]->product_id);
		}
		$this->view('blog/detail', $data);
	}

}
?>